package com.example.ticket.service.impl;

import com.example.ticket.entity.Ban;
import com.example.ticket.mapper.BanMapper;
import com.example.ticket.service.BanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.TimeUnit;

@Service
public class BanServiceimpl implements BanService {
    @Autowired
    BanMapper banMapper;


    @Autowired
    RedisTemplate redisTemplate;


    @Override
    public Ban insertBan(Ban ban){
        int res=banMapper.insertBan(ban);
        if(res==1){
            redisTemplate.opsForValue().set("ban_"+ban.getUserId(),ban,20, TimeUnit.MINUTES);
        }
        return ban;
    }

    @Override
    public List<Ban> Banlist(){
        List<Ban> list = banMapper.Banlist();
        return list;
    }
}
